package com.example.day15_7_15_1.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.day15_7_15_1.R;
import com.example.day15_7_15_1.bean.Bean;

import java.util.ArrayList;
import java.util.List;

public class InfoRclAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<Bean.DataBean.DatasBean> list = new ArrayList<>();

    public InfoRclAdapter(Context context) {
        this.context = context;
    }

    public void setList(List<Bean.DataBean.DatasBean> list) {
        this.list.addAll(list);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.layout_item, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.tvItem.setText(list.get(position).getDesc());
        Glide.with(context).load(list.get(position).getEnvelopePic()).into(viewHolder.imgItem);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvItem;
        ImageView imgItem;
        public ViewHolder(View inflate) {
            super(inflate);
            tvItem = inflate.findViewById(R.id.tv_item);
            imgItem = inflate.findViewById(R.id.img_item);
        }
    }
}
